/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __C74BEACE_2859_47a0_AD02_30B286F6A37F__
#define __C74BEACE_2859_47a0_AD02_30B286F6A37F__

#include "../tools/head.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos_box
{
    // 
    // threads_impl
    // 
    class threads_impl : public xos_stl::mem_item< xos::release_impl< threads_impl >, thread_lock >,
        public i_threads
    {
    public:
        typedef xos::release_impl< threads_impl > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //

        static int get_xos_item_data( ITEM_DATA*& item_ptr );

    public:
        threads_impl();
        ~threads_impl();

    private:
        i_callback * helper_new_thread( int nMsgNum );
        i_callback * helper_notify( i_msg *& pMsg );
        int get_cpu_num();
        int init_data();

    private:
        i_list_iter * m_pThreadListIter;
        i_list * m_pThreadList;

        int m_nTaskNumForNewThread;
        int m_nMaxThreadNum;

    public:
        // 
        // nNum = 0, means cpu core num
        // if not set, default is 0
        // 
        int set_max_thread_num( int nNum );
        int get_max_thread_num();

        i_callback * notify( i_msg *& pMsg );
        i_callback * get_thread_dispatch();
        i_callback * get_thread_in_order();

    public:
        int init();
        int term();

    };
} // xos

#endif // __C74BEACE_2859_47a0_AD02_30B286F6A37F__
